<?php
/**
 * Desc: 获取积分控制器
 * Created by chenxinxing
 * Date: 2018-08-15
 */
namespace App\Http\WechatAuth\Controllers;

use App\Api\BaseClass\Controller;
use App\Http\WechatAuth\Models\User;
use App\Http\WechatAuth\Models\UserIntegralLog;
use App\Http\WechatAuth\Services\AuthContract;
use App\Core\Facades\User as UserFacades;

class GetIntegralController extends Controller{

    public function __contruct(AuthContract $auth)
    {
        parent::__construct();
    }



    /**
     * 获取当前积分和总积分
     */
    public function getIntegral(){
    
        $info = User::where('id',UserFacades::user()->id)->select('total_integral','integral')->get();
        return $this->form->datas($info);
    }

    /**
     * 获取账户详情
     */
    public function getIntegralDetail(){
        
        $rules = [
            ['offset', 'required|integer'],
            ['limit', 'required|integer']
        ];
        $params = $this->form->camelFormOrFail($rules);
        $search_params = [
            ['orderBy','created_at','desc'],
            ['where','uid',UserFacades::user()->id],
        ];
        $UserIntegralLog = (new UserIntegralLog)->pagination($params, $search_params);
        return $this->form->getMessage($UserIntegralLog);
    }
}


